<template>
	<view>
		<button @click="getjs">授权</button>
	</view>
</template>

<script>
	import http from "../../utils/request.js"
	export default {
		data() {
			return {
				appid:"wxbe7267bb80b370bf",
				secret:"f15bc2a7d6beab610a945b33215926f3"
			};
		},
		methods: {
			getjs() {
				let that = this
				uni.getUserProfile({
					desc: "desc",
					success: (res) => {
						console.log(res, 19);
						uni.setStorageSync("userInfo", res.userInfo)
						let {
							nickName,
							avatarUrl
						} = res.userInfo
						uni.login({
							success: (res1) => {
								console.log(res1, 24);
								let {
									code
								} = res1
								http({
									url: "/wx_login",
									method: 'post',
									data: {
										appid:that.appid,
										secret:that.secret,
										nickName,
										avatarUrl,
										code
									}
								}).then(res2 => {
									console.log(res2, 31);
									uni.setStorageSync("user_Token",res2.data.data.user_Token)
									uni.navigateBack()
								})
							}
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">

</style>
